﻿using System;
using System.Threading.Tasks;
using UnityEngine;

public class PLTweenTool : MonoBehaviour
{
    public Transform a;
    public Transform b;
    public Transform moveObj;

    public void Start()
    {
        Move(a, b, moveObj, 3f);
    }


    public async void Move(Transform a, Transform b, Transform moveObj, float time)
    {
        float dis = Vector3.Distance(a.position, b.position);
        var c = b.position - a.position;

        var speed = c / time;

        float timeCount = 0f;
        float interval = 0.01f;

        while (true)
        {
            await Task.Delay(TimeSpan.FromSeconds(interval));
            timeCount += interval;
            moveObj.position += speed * interval;
            if (timeCount >= time)
            {
                break;
            }
        }
    }



}
